﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using SysMisc;

namespace Kernel
{

    public class ProjectConfig
    {
        public ProjectConfig()
        {
            MainCfg = new Kernel.xmlMainConfig();
            MainPrint = new Kernel.xmlPrintMain();
            Catalogues = new List<xmlCatalogue>();
            Files = new List<xmlFile>();
        }

        [XmlElement("MainConfig")]
        public xmlMainConfig MainCfg { get; set; }  //主配置
        [XmlElement("PrintMain")]
        public xmlPrintMain MainPrint { get; set; } //打印全局配置
        [XmlArray("Catalogues")]
        public List<xmlCatalogue> Catalogues { get; set; } //目录项
        [XmlArray("Files")]
        public List<xmlFile> Files { get; set; }    //本工程文件项

        public static ProjectConfig LoadProjectFile(string path)
        {
            ProjectConfig _prj_config = Serialization.DeSerializeFromXml<ProjectConfig>(path);
            return _prj_config;
            //return null;
        }
    }
    [XmlType(TypeName = "MainConfig")]
    public class xmlMainConfig
    {
        public xmlMainConfig()
        {
            Version = "V1.0";
            PrjName = "N/A";
            CmpyCode = "443";
            PrjCode = "N/A";
            State = "N/A";
            Subject = "N/A";
            VolName = "N/A";
            VolNum = 1;
            RowNum = 0;
            PubDate = "N/A";
            StartNum = 1;
        }
        [XmlAttribute]
        public string Version { get; set; }/*版本名称*/
        [XmlAttribute]
        public string PrjName { get; set; }/*工程名称*/
        [XmlAttribute]
        public string CmpyCode { get; set; }/*公司编码*/
        [XmlAttribute]
        public string PrjCode { get; set; }/*工程编号*/
        [XmlAttribute]
        public string State { get; set; }/*阶段名称*/
        [XmlAttribute]
        public string Subject { get; set; }/*专业名称*/
        [XmlAttribute]
        public string VolName { get; set; }/*卷册名称*/
        [XmlAttribute]
        public int VolNum { get; set; }/*卷号*/
        [XmlAttribute]
        public int RowNum { get; set; }/*册号*/
        [XmlAttribute]
        public string PubDate { get; set; }/*出版日期*/
        [XmlAttribute]
        public int StartNum { get; set; }/*起始编号*/
    }
    [XmlType(TypeName = "PrintMain")]
    public class xmlPrintMain
    {
        public xmlPrintMain()
        {
            this.CopyNum = 1;
            this.ByInverse = true;
            this.ByCollate = true;
            this.BySize = true;
        }
        [XmlAttribute]
        public string PrinterName { get; set; }/*打印机名称*/
        [XmlAttribute]
        public int CopyNum { get; set; }/*打印份数*/
        [XmlAttribute]
        public bool ByCollate { get; set; }/*逐份打印*/
        [XmlAttribute]
        public bool ByInverse { get; set; }/*逆序打印*/
        [XmlAttribute]
        public bool BySize { get; set; }/*逐尺寸打印*/
    }
    [XmlType(TypeName = "PrintConfig")]
    public class xmlPrintConfig
    {
        public xmlPrintConfig()
        {
            this.CopyNum = 1;
            this.ByInverse = true;
            this.ByCollate = true;
            this.BySize = true;
        }
        [XmlAttribute]
        public string PrinterName { get; set; }/*打印机名称*/
        [XmlAttribute]
        public int CopyNum { get; set; }/*打印份数*/
        [XmlAttribute]
        public bool ByInverse { get; set; }/*逆序打印*/
        [XmlAttribute]
        public bool ByCollate { get; set; }/*逐份打印*/
        [XmlAttribute]
        public bool BySize { get; set; }/*逐尺寸打印*/
    }
    /// <summary>
    /// 目录类
    /// </summary>
    [XmlType(TypeName = "Catalogue")]
    public class xmlCatalogue : IComparable<xmlCatalogue>
    {
        public xmlCatalogue()
        {
            IsCustomer = false;
            IsPrint = true;
            OrderSeed = -1;
        }
        [XmlAttribute]
        public string FileName { get; set; }/*文件名*/
        [XmlAttribute]
        public string FileType { get; set; }/*文件类型（*.dwg,*.doc,*.xls）*/
        [XmlAttribute]
        public string PaperCode { get; set; }/*图纸编号*/
        [XmlAttribute]
        public string PaperName { get; set; }/*图纸名称*/
        [XmlAttribute]
        public string PaperCount { get; set; }/*图纸张数*/
        [XmlAttribute]
        public string PaperType { get; set; }/*图纸类型*/
        /// <summary>
        /// 图纸规格（图框的名称）
        /// </summary>
        [XmlAttribute]
        public string PaperSpec { get; set; }/*图纸规格（图框的名称），应该根据*/
        //[XmlAttribute]
        //public int PaperObjectId { get; set; }/*图框在数据库中的唯一ID*/
        //[XmlAttribute]
        //public xmlPrintConfig PrinterConfig { get; set; }/*打印机配置*/

        public int PaperObjectId;/*图框在数据库中的唯一ID*/
        public bool IsCustomer { get; set; }/*是自定义的吗*/
        public bool IsNoNum { get; set; }/*是否编码*/
        public bool IsPrint { get; set; }/*是否打印*/

        /// <summary>
        /// 排序用变量
        /// </summary>
        public int OrderSeed;
        public object Tag;

        //实现排序接口
        public int CompareTo(xmlCatalogue ctg_cmp)
        {
            return this.OrderSeed - ctg_cmp.OrderSeed;
        }
    }
    [XmlType(TypeName = "File")]
    public class xmlFile
    {
        [XmlAttribute]
        public string FileName { get; set; }/*文件名*/
        [XmlAttribute]
        public string FileType { get; set; }/*文件类型*/
    }
}
